var banner_index=1;
var banner = document.querySelector(".banner");
var banner_img = banner.querySelectorAll("img");
var banner_span = banner.querySelectorAll("span");
function slide(n){
    // 初始化
   for(let i=0;i<banner_img.length;i++){
    banner_img[i].style.display = 'none';
    banner_span[i].className = "";
   }
   if(banner_index<1){banner_index=banner_img.length};
   if(banner_index>banner_img.length){banner_index=1};
   banner_img[banner_index-1].style.display = "block";
   banner_span[banner_index-1].className = "active";
}
function banner_p(n){
    slide(banner_index+=n);
}
function banner_span_click(n){
    slide(banner_index=n)
}

slide(banner_index);

// auto,slide;

var timer = null;

function auto(){
    if(!timer){
        timer = setInterval(() => {
            banner_index++;
            slide(banner_index);
        }, 2000);
    }
}

timer = setInterval(() => {
    banner_index++;
    slide(banner_index);
}, 2000);

banner.addEventListener("mouseenter",()=>{
    clearInterval(timer)
    timer = null
}
)
banner.addEventListener("mouseleave",()=>{
    auto()
})